import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:provider/provider.dart';
import '../../utils/dio_util.dart';
import '../../provider/cart.dart';
class Bottom extends StatefulWidget {
  Bottom({ this.count, this.amount,this.cartIdList});


  final int count;
  final double amount;
  final List cartIdList;


  @override
  _BottomState createState() => _BottomState();
}

class _BottomState extends State<Bottom> {
  int _count;
  double _amount;
  List _cartIdList;
  //去结算
  doCheckOut() async {
    Navigator.of(context).pushNamed('/checkOut');
  }

  //删除购物车
  Future<Map<String,dynamic>> delCart(cardIds) async{
    String api = '/api/mall/cart/remove.service';
    DioUtil http = DioUtil();
    Map<String, dynamic> res = await http.get(api,data:{"cardIds":cardIds});
    print(res);
    return res;
  }



  @override
  void initState() {
    super.initState();
    setState(() {
      _count = widget.count;
      _amount = widget.amount;
      _cartIdList = widget.cartIdList;
    });

  }

  @override
  Widget build(BuildContext context) {
    var cart=Provider.of<Cart>(context);
    return Container(
      decoration: BoxDecoration(
        border: Border(top: BorderSide(width: 1, color: Colors.black12)),
        color: Colors.white,
      ),
      width: 750.w,
      height: 78.h,
      child: Row(
        children: <Widget>[
          Align(
            alignment: Alignment.centerLeft,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Container(
                  width: 78.w,
                  child: Checkbox(
                    value: cart.isAll,
                    activeColor: Colors.red,
                    onChanged: (val) {
                      if(val){
                        cart.setSelectCart(_cartIdList);
                      }else{
                        cart.setSelectCart([]);
                      }
                      cart.setAllSelect(val);
                    },
                  ),
                ),
                RichText(
                  text: TextSpan(children: [
                    TextSpan(text: "全选",style: TextStyle(
                      color: Colors.black54
                    )),
                    TextSpan(text: "($_count)",style: TextStyle(
                        color: Colors.black54
                    )),
                  ]),
                ),

              ],
            ),
          ),
          cart.isEdit == false
              ? Expanded(
                  child: Align(
                    alignment: Alignment.centerRight,
                    child: Container(
                      width: 400.w,
                      child: Row(
                        children: [
                          Text("￥${_amount}",
                              style: TextStyle(fontSize: 35.sp, color: Colors.red)),
                          SizedBox(width: 20),
                          Container(
                            width: 220.w,
                            child: RaisedButton(
                              shape: RoundedRectangleBorder(
                                  borderRadius:
                                  BorderRadius.all(Radius.circular(50))),
                              child:
                              Text("立即下单", style: TextStyle(color: Colors.white)),
                              color: Colors.red,
                              onPressed: doCheckOut,
                            ),
                          )
                        ],
                      ),
                    ),
                  ),
                )
              : Expanded(
                  child: Align(
                    alignment: Alignment.centerRight,
                    child: Container(
                      width: 380.w,
                      child: Row(
                        children: [
                          Container(
                            height:60.w,
                            width:160.w,
                            child: OutlineButton(
                                shape: RoundedRectangleBorder(
                                    borderRadius:
                                    BorderRadius.all(Radius.circular(50))),
                                child:
                                Text("收藏", style: TextStyle(color: Colors.red)),
                                color: Colors.red,
                                onPressed: () {},
                                borderSide:BorderSide(color: Colors.red)
                            ),
                          ),
                          SizedBox(
                            width: 25.w,
                          ),
                          Container(
                            height:60.w,
                            width:160.w,
                            child: OutlineButton(
                              shape: RoundedRectangleBorder(
                                  borderRadius:
                                  BorderRadius.all(Radius.circular(50))),
                              child:
                              Text("删除", style: TextStyle(color: Colors.grey)),
                              color: Colors.red,
                              onPressed: () {
//                                delCart();
                              },
                            ),
                          )
                        ],
                      ),
                    ),
                  ),
                )
        ],
      ),
    );
  }
}
